package com.pureut.storage.controller;

import com.pureut.storage.dto.MiscellaneousReceiptDto;
import com.pureut.storage.dto.PickingRestDbDto;
import com.pureut.storage.dto.PickingRestHandoverDto;
import com.pureut.storage.export.MiscellaneousPurchaseReceiptExport;
import com.pureut.storage.service.MiscellaneousReceiptService;
import com.pureut.storage.util.ExcelUtil;
import com.pureut.storage.vo.MiscellaneousReceiptVo;
import com.pureut.storage.vo.PickingRestDbVo;
import com.pureut.storage.vo.UpdateStatusByQualityVo;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/***
 * 其它入库控制层
 * Author:C
 * Date:2022/12/28 15:47
 * @DESC
 */
@RestController
@RequestMapping("/miscellaneous-receipt")
public class MiscellaneousReceiptController extends BaseController {

    @Resource
    MiscellaneousReceiptService miscellaneousReceiptService;

    /**
     * 获取其它入库分页列表
     */
//    @RequiresPermissions("warehouse:warehousing:other:list")
    @GetMapping("/list")
    public TableDataInfo<MiscellaneousReceiptDto> getList(MiscellaneousReceiptVo miscellaneousReceiptVo, PageQuery pageQuery) throws Exception {
        //查询委外入库列表
        return miscellaneousReceiptService.getMiscellaneousList(miscellaneousReceiptVo,pageQuery);
    }

    /**
     * 新增其它入库
     */
//    @RequiresPermissions("warehouse:warehousing:other:add")
    @Log(title = "新增其它入库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody MiscellaneousReceiptVo miscellaneousReceiptVo) throws Exception {
        return toAjax(miscellaneousReceiptService.addMiscellaneousReceipt(miscellaneousReceiptVo));
    }

    /**
     * 关结其它入库
     */
//    @RequiresPermissions("warehouse:warehousing:other:closing")
    @Log(title = "关结其它入库", businessType = BusinessType.UPDATE)
    @PostMapping("/close")
    public R<Void> close(@RequestBody MiscellaneousReceiptVo miscellaneousReceiptVo) {
        return toAjax(miscellaneousReceiptService.close(miscellaneousReceiptVo));
    }

    /**
     * 删除其它入库
     */
//    @RequiresPermissions("warehouse:warehousing:other:remove")
    @Log(title = "删除其它入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{idStr}")
    public R<Void> deleteMiscellaneousReceipt(@PathVariable("idStr") String idStr) {
        return toAjax(miscellaneousReceiptService.deleteMiscellaneousReceipt(idStr));
    }

    /**
     * 修改其它入库
     */
//    @RequiresPermissions("warehouse:warehousing:other:edit")
    @Log(title = "修改其它入库", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R<Void> updateMiscellaneousReceipt(@Validated @RequestBody MiscellaneousReceiptVo miscellaneousReceiptVo) {
        return toAjax(miscellaneousReceiptService.updateMiscellaneousReceipt(miscellaneousReceiptVo));
    }

    /**
     * 查看
     */
//    @RequiresPermissions("warehouse:warehousing:other:query")
    @GetMapping("/view/{id}")
    public R<MiscellaneousReceiptDto> view(@PathVariable("id") Long id) {
        return R.ok(miscellaneousReceiptService.getView(id));
    }

    /**
     * 导出
     */
//    @RequiresPermissions("warehouse:warehousing:other:export")
    @PostMapping("/miscellaneousMessageExport")
    public R<Void> miscellaneousMessageExport(HttpServletResponse response, MiscellaneousReceiptVo miscellaneousReceiptVo) throws IOException {
        List<MiscellaneousPurchaseReceiptExport> infoExport = miscellaneousReceiptService.getInfoExport(miscellaneousReceiptVo);
        ExcelUtil<MiscellaneousPurchaseReceiptExport> excelUtil = new ExcelUtil<MiscellaneousPurchaseReceiptExport>(MiscellaneousPurchaseReceiptExport.class);
        excelUtil.excelWriter(response, infoExport, "其它入库信息.xlsx");
        return R.ok();
    }

    /**
     * 其它入库（pda）
     */
//    @RequiresPermissions("warehouse:warehousing:other:warehousing")
    @PostMapping("/miscellaneousPDA")
    @Log(title = "其它入库(pda)", businessType = BusinessType.UPDATE)
    public R<PickingRestDbDto> miscellaneousPda(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(miscellaneousReceiptService.miscellaneousPda(pickingRestDbVo));
    }

    /**
     *其它入库拣货撤销
     */
    @PostMapping("/pickingCancellation")
    @Log(title = "其它入库拣货撤销", businessType = BusinessType.UPDATE)
    public R<Void> pickingCancellation(@RequestBody PickingRestDbVo pickingRestDbVo) {
        return toAjax(miscellaneousReceiptService.pickingCancellation(pickingRestDbVo));
    }

    /**
     * 其它入库拣货完成
     */
    @PostMapping("/pickingCompleted")
    @Log(title = "其它入库拣货完成", businessType = BusinessType.UPDATE)
    public R<Void> pickingCompleted(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return toAjax(miscellaneousReceiptService.pickingCompleted(pickingRestDbVo));
    }

    /**
     * 其它入库交接
     */
//    @RequiresPermissions("warehouse:warehousing:other:handover")
    @PostMapping("/handover")
    @Log(title = "其它入库交接", businessType = BusinessType.UPDATE)
    public R<PickingRestHandoverDto> handover(@RequestBody PickingRestDbVo pickingRestDbVo) {
        return R.ok(miscellaneousReceiptService.handover(pickingRestDbVo));
    }

    /**
     * 其他入库品质回传状态(fegin调用)
     */
    @PostMapping("/updateMiscellaneousReceiptByQuality")
    public R<Void> updateMiscellaneousReceiptByQuality(@RequestBody UpdateStatusByQualityVo updateStatusByQualityVo) {
        return toAjax(miscellaneousReceiptService.updateStatusByQuality(updateStatusByQualityVo));
    }

}
